package main

import (
	"fmt"
	"sync"
)

var wg3 sync.WaitGroup

func write3(ch chan<- int) {
	defer wg3.Done()
	for i := 0; i < 10; i++ {
		ch <- i
	}
	//<- ch // invalid operation: <-ch (receive from send-only type chan<- int)
	close(ch)
}

func read(ch <-chan int) {
	defer wg3.Done()
	for {
		if val, ok := <-ch; ok {
			fmt.Println(val)
		} else {
			break
		}
	}
}

func main() {
	ch := make(chan int, 10)
	wg3.Add(2)
	go write3(ch)
	go read(ch)
	wg3.Wait()

}
